简体   繁体   中英

Get value of a jquery element?

var $x = $("input[name='" + linkedmodule + "']");
//var x=document.getElementsByName(linkedmodule);

console.log($x);
if ($x !== "" || $x !== "undefined" || $x !== null) {
    linkedid = $x.val();
    linked_module = $x.attr("relatedModule");
    console.log(linkedid);
} else {

}

I am getting an undefined in the linkedid Please could someone help me

In the above code object ($x) empty check is not proper,

Below is the modified code

var $x = $("input[name='" + linkedmodule + "']");
//var x=document.getElementsByName(linkedmodule);

console.log($x);
if (!($x === undefined || $x == null || $x.length <= 0)) {
    linkedid = $x.val();
    linked_module = $x.attr("relatedModule");
  console.log("Value of the element : "+ linkedid);
} else {

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM