我想要做到以下幾點: 2 div,clickable返回div的「值」。這是通過在div上創建(內部)get_value函數來實現的。訪問自定義內部函數JQueryFunction
但我真正想要的是有一個按鈕,通過調用get_value函數讀取div的值。例如,請參閱以下代碼。
不幸的是我不能得到它的工作....
我曾試圖讓全球價值觀,但隨即又被覆蓋......
任何線索?
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Js/jquery-1.10.2.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
initdiv("a", 10)
});
$(document).ready(function() {
initdiv("b", 20)
});
function initdiv(id, value) {
function get_value() {
return value;
};
$("#" + id).click(function() {
alert(get_value());
});
}
function getFoo() {
var obj = $("#a");
alert(obj.get_value());
}
</script>
</head>
<body>
<form id="form2" runat="server">
<div id="a">
foo
</div>
<div id="b">
bar
</div>
<input type="button" onclick="getFoo();" value="click me and get the value of DIV 'foo'" />
</form>
</body>
</html>
爲什麼不把值在DOM和檢索它的點擊? –