Move onclick="touch(event) from .html to Javascript file -


मेरे पास .htlm फ़ाइल में एक div है:

  & lt; div id = "स्पर्श" ऑनक्लिक = "टच (इवेंट)" & gt; & lt; / div & gt;  

मैं इस div को .html फ़ाइल में इस तरह कैसे बना सकता हूं:

  & lt; div id = "touch" & gt; & lt; / div & gt;  

और फिर मेरी .js फ़ाइल में मैं इसे "क्लिक" पर एक "if" कथन के भीतर बनाना चाहता हूं: (मैं "enableTouch" के लिए config.js फ़ाइल में एक स्विच है) )

  यदि (enableTouch == सच) {document.getElementById ('स्पर्श') ... मुझे क्लिक करने पर सक्रिय करने के लिए यहां क्या करना होगा? एनिमेशन कोड यहाँ। }  

धन्यवाद।

फिर भी काम नहीं करता: यह काम करता है अगर मैं बाहर ले जाता हूं:

  "document.getElementById (' स्पर्श ')। Onclick = स्पर्श; "  

और .html में div को परिवर्तित करें:

  & lt; div id = "touch" onclick = "touch (event)" & gt; & lt ; / div & gt;  

धन्यवाद फिर से।

  // यदि ((EnableTouchToDisplayHourlyForecast == सच) & amp; amp; (एनिमेशन केवल == गलत)) {document.getElementById ( 'स्पर्श')। Onclick = स्पर्श; Var touchend = false; फ़ंक्शन स्पर्श (ईवेंट) {var element = event.currentTarget; अगर (touchend) {touchend = false; । Document.getElementById ( "forecastContainer") style.opacity = "1.0"; । Document.getElementById ( "forecastContainer") style.webkitTransform = "पैमाने (1.0,1.0)"; । Document.getElementById ( "hourlyForecastContainer") style.opacity = "0.0"; । Document.getElementById ( "hourlyForecastContainer") style.webkitTransform = "पैमाने (0.0,0.0)"; } Else {touchend = true; । Document.getElementById ( "forecastContainer") style.opacity = "0.0"; । Document.getElementById ( "forecastContainer") style.webkitTransform = "पैमाने (0.0,0.0)"; । Document.getElementById ( "hourlyForecastContainer") style.opacity = "1.0"; । Document.getElementById ( "hourlyForecastContainer") style.webkitTransform = "पैमाने (1.0,1.0)"; }} <}  

इस तरह से:

  यदि (सक्षम टच) {document.getElementById ('स्पर्श')। Onclick = स्पर्श; }  

यदि जेएस स्क्रिप्ट को आपके पेज के शरीर से पहले शामिल किया गया है, तो आपको इसे onload हैंडलर में करने की आवश्यकता होगी:

  window.onload = function () {if (enableTouch) {document.getElementById ('स्पर्श')। Onclick = touch; } // अन्य ओनलोड सामान}; Var touchend = false; फ़ंक्शन स्पर्श (ईवेंट) {// ...}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -