為什么用按鈕調(diào)用函數(shù)的方法沒有反應(yīng)?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
? ? <title>SetTimeout</title>
? ? <script src="http://code.jquery.com/jquery-1.11.3.js"></script> ? ? ? ??
? ? <script type="text/javascript">
? ? ? ? $(document).ready(function fun() {
? ? ? ? ? ? //var $div = $('div'); //jQuery對象
? ? ? ? ? ? //var div = $div.get(0);
? ? ? ? ? ? //div.style.color = 'red'; //操作dom對象的屬性
? ? ? ? ? ? var div = document.getElementsByTagName('div');
? ? ? ? ? ? var $div = $(div);
? ? ? ? ? ? var $first = $div.first();
? ? ? ? ? ? $first.css = ('color', 'blue');
? ? ? ? });
? ? </script>
</head>
<body >
<div id ="id">javascript
? ? <p>javascript</p><div id="di">jQuery</div><h5>PHP</h5></div>
? ? <input value="button" type="button" onclick="fun()" />
? ? <div>元素一</div>
<div>元素二</div>
<div>元素三</div>
</body>
2018-12-05
css?是一個函數(shù),它需要參數(shù)
2018-11-19
謝謝你??!我發(fā)現(xiàn)問題就出在$first.css = ('color', 'blue')這里,這里不能用等號。好像和src沒有太大關(guān)系,我也不太懂兩個src有什么區(qū)別。。
2018-11-17
你把<script src="http://code.jquery.com/jquery-1.11.3.js"></script>?
的src改成http://idcbgp.cn/static/lib/jquery/1.9.1/jquery.js
再把?$first.css = ('color', 'blue');
改成?$first.css('color', 'blue');
就可以了
而且$(document).ready(function(){})的作用是在頁面加載完以后就運行函數(shù),不需要再加一個onclick來運行函數(shù)