js与jQuery在页面取值的方法

tech2025-05-21  1

js与jQuery在页面取值的方法

1: 根据class 、 id 取 input 标签的value 值 。 jQuery : $(".className").val(); $("#idName").val(); javaScript : document.getElementById("idName").value; 2: 根据class 、id 获取标签之间的内容:如 <span> 、<lable> 、<div> 。 jQuery : $("#idName").html(); $(".className").html(); javaScript : document.getElementById("idName").innerHTML ; 3: 获取<select id='selectId'> <option value='selectValue'> 选中值: jQuery : $("#selectId").val(); javaScript : document.getElementById("selectId").value; 4: 获取<img > 的 src 内容 : jQuery : $("#imgId")[0].src; javaScript : document.getElementById("imgId").src; 5:子界面获取父界面元素内容: 5.1 (标签间的内容 ,如 <span> 、<lable> 、<div> ) JavaScript : window.parent.document.getElementById("currentPage").innerHTML ; JQuery : $(window.parent.document).find("#IdName").text(); 5.2 (取 input 标签的value 值) JavaScript : window.parent.document.getElementById("currentPage").value ; JQuery : $(window.parent.document).find("#IdName").val(); 6:子界面控制父页面跳转: window.parent.location.href = “*” ;
最新回复(0)