कोड तुम्हें तैनात जीता नहीं है जैसा कि आप उम्मीद करते हैं, काम नहीं करते हैं, आप यहां क्या कर रहे हैं यह जांच कर रहा है कि विशेषता-मूल्य क्या है नामांकित विशेषता ("data-params"
) "undefined"
के बराबर है, जो true
वापस लौटाएगी यदि विशेषता data-params="undefined"
है।
if (object.getAttribute("data-params") === "undefined") {
// the "data-params" attribute-value is exactly "undefined"
// note that `getAttribute()` is a
}
मैं क्या संदेह है कि आप क्या करना चाहते है:
var typeOfObjectAttribute = typeof object.getAttribute("data-params");
if (typeOfObjectAttribute === null || typeOfObjectAttribute === "") {
// data-params attribute doesn't exist on that Node.
}
ध्यान दें कि – अनुसार (Element.getAttribute()
के लिए संदर्भ में, नीचे) मोज़िला डेवलपर नेटवर्क – कहा गया है कि:
getAttribute()
तत्व पर एक निर्दिष्ट विशेषता का मान देता है। यदि दिया गया विशेषता मौजूद नहीं है, तो लौटाए गए मान या तो null
या ""
(खाली स्ट्रिंग) और नरकिप होगा;
यह भी ध्यान देने योग्य है कि getAttribute()
जेनेरिक ऑब्जेक्ट्स की बजाय एलिमेंट नोड्स का एक तरीका है।
// here we look to see if the 'params' key is present in the
// HTMLElement.dataset object of the element, and then invert
// that result using the '!' operator, to check that the
// attribute *isn't* present:
if (!('params' in document.getElementById('elementID').dataset)) {
// the data-params attribute is not present.
}
संदर्भ::
स्रोत
2015-08-27 13:07:18
'अगर (typeof obj [" डेटा-विशेषता "]! ==" अपरिभाषित ") {// यहाँ कोड}' –