大家好,我很新的jQuery和CSS和我試圖訪問以下內容:訪問元素的onclick
我試圖在onclick功能「檢查checkForAppointment'4個span標籤中的值。
HTML:
<div align="thun" id="clientScheduleWeek" data-role="page" data-theme="a">
<div data-role="header" data-theme="a">
<a href="#" onclick="JUMPclientDetails()">Back</a>
<h1>Client Details</h1>
</div>
<div data-role="content">
<div id="weekViewBubble">
<ul data-count-theme="b" data-inset="true" data-role="listview" data-theme="c">
<li onClick="checkForAppointment();"><a>Monday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
<li onClick="checkForAppointment();"><a>Tuesday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
<li onClick="checkForAppointment();"><a>Wednesday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
<li onClick="checkForAppointment();"><a>Thursday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
<li onClick="checkForAppointment();"><a>Friday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
<li onClick="checkForAppointment();"><a>Saturday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
<li onClick="checkForAppointment();"><a>Sunday <span class="ui-li-count ui-btn-corner-all countBubl">0</span></a></li>
</ul>
</div>
</div>
</div>
我開始嘗試:
function checkForAppointment(){
console.log('getting to the function anyway');
var j = $('ul li').eq(0).value;
var k = $('ul li').eq(1).value;
console.log('j is ' + j + ' and k is '+ k);
};
兩個J和K在這一點上是不確定的
編輯:
: 功能由lolka_bolka建議function checkForAppointment(){
var AptBool=false;
$('.something').click(function() {
console.log('we have entered the .click function');
//Get all the span inside of it
var collection = $(this).find('span');
//Loop through all span object
$.each(collection, function(idx, obj) {
if ($(obj).html() > 0){
AptBool=true;
//return;
}
//Write the html value of span to the console.
//console.log('value here is ' + $(obj).html());
});
if (!AptBool){
alert('There is no appointment to view');
return;
}
});
//console.log('getting to the function anyway');
//var j = $('ul li').eq(0).text();
//var k = $('ul li').eq(1).text();
//console.log('j is ' + j + ' and k is '+ k);
};
難道這應該是XML或HTML? ' http://54.72.173.92/console.png' – Brewal 2014-11-05 15:02:57
向我們展示您的html請在您的問題中,而不是在圖片上。 – vaso123 2014-11-05 15:03:02
jQuery中的所有方法都會返回一個jQuery對象,這是一個DOM集合的包裝器對象。因此,當您調用.eq(0)時,將返回表示集合元素集的jQuery對象。要獲得該值,您可以調用.eq(0).val() – edrian 2014-11-05 15:04:33