0
我的代碼中的If - Else語句似乎在導致錯誤。點擊圖片時,如果圖片尺寸爲100px×100px,並且在任何其他情況下打開了雅虎窗口,我都會嘗試打開Google窗口。任何想法是什麼使if語句出錯?爲什麼我的if語句在jquery中檢測不到圖像大小?
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#testImgID").click(function(){
var imgWidth = $(this).width();
var imgHeight = $(this).height();
if(imgWidth == 100 && imgHeight == 100)
{
window.open("http://www.google.com");
else
{
window.open("http://www.yahoo.com");
}
});
});
<p>
<img width="100" height="100" id="testImgID" alt="Setup client email capture.jpg" src="/wg/PayrollSolutions/PublishingImages/RCP_setups_theatrical_assignedTo_table.png" style="margin: 5px"/>
</p>
謝謝馬科斯!我沒有意識到if-else語句需要兩個右括號。 – shampouya
如果你打開一個支架,你必須始終關閉它;)他們成對:) –