"ऑनचेंज" ईवेंट तभी ट्रिगर होता है जब उपयोगकर्ता कुछ मूल्य में प्रवेश करता है। जब मैं जावास्क्रिप्ट के माध्यम से स्वचालित रूप से मूल्य बदलता हूं तो ईवेंट को आग लगाना क्यों संभव नहीं है? क्या कोई विकल्प है?ट्रिगर "ऑनचेंज" ईवेंट
एनिमेशन:
कोड:
<!DOCTYPE html>
<html>
<head>
<script>
document.addEventListener ("DOMContentLoaded", function() {
var input = this.getElementsByTagName ("input")[0];
var div = this.getElementsByTagName ("div")[0];
var i = 0;
var seconds = 5;
div.innerHTML = "The following input should fire the event in " + seconds + " seconds";
var interval = window.setInterval (function() {
i ++;
if (i === seconds) {
window.clearInterval (interval);
input.value = "Another example";
div.innerHTML = "Nothing ! Now try change the value manually";
}
else {
div.innerHTML = "The following input should fire the event in " + (seconds - i) + " seconds";
}
}, 1000);
input.addEventListener ("change", function() {
alert ("It works !");
}, false);
}, false);
</script>
<style>
body {
padding: 10px;
}
div {
font-weight: bold;
margin-bottom: 10px;
}
input {
border: 1px solid black;
border-radius: 3px;
padding: 3px;
}
</style>
<title>Event</title>
</head>
<body>
<div></div>
<input type = "text" value = "Example" />
</body>
</html>
धन्यवाद
आपको मूल्य बदलने के बाद मैन्युअल रूप से ईवेंट को आग लगाना होगा। यह प्रश्न देखें: http://stackoverflow.com/q/2490825/615754 – nnnnnn
जब आप जावास्क्रिप्ट के साथ इनपुट मान बदलते हैं तो कुछ घटनाओं को फायर क्यों नहीं करते? आप विनिमय का उपयोग क्यों करना चाहते हैं? आदान-प्रदान उपयोगकर्ता इनपुट के लिए बाकी है जिसे आप स्वयं के बिना संभाल सकते हैं। – ggzone