मैं वर्तमान तत्व की आईडी को अलर्ट करने के लिए निम्न कोड का उपयोग कर रहा हूं।वर्तमान तत्व की चेतावनी आईडी
<input type="text" id="desc" name="txtTitle" onclick="fun()">
jQuery:
function fun() {
var currentId = $(this).attr('id');
alert(currentId);
}
ऐसा क्यों है "अनिर्धारित" सचेत करता है? मैं के साथ की कोशिश की है:
var currentId =$('element').attr('id');
// and
alert($(this).id);
// and
alert(this.id);
लेकिन यह अलर्ट undefined
यदि आपने ऑनक्लिक हैंडलर जोड़ने के लिए jQuery का उपयोग किया है, तो आप यह नहीं पूछेंगे। :) – epascarello