先看代码:
代码
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5
6 <script type="text/javascript">
7 function test() {
8 var s = document.getElementById("select1");
9 s.setAttribute("onchange", "show('"+s.value+"');");
10 }
11 function show(m) {
12 alert(m);
13 }
14 </script>
15
16 </head>
17 <body onload="test()">
18 <select id="select1">
19 <option value="a">a</option>
20 <option value="b">b</option>
21 <option value="c">c</option>
22 </select>
23 </body>
24 </html>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title></title>
5
6 <script type="text/javascript">
7 function test() {
8 var s = document.getElementById("select1");
9 s.setAttribute("onchange", "show('"+s.value+"');");
10 }
11 function show(m) {
12 alert(m);
13 }
14 </script>
15
16 </head>
17 <body onload="test()">
18 <select id="select1">
19 <option value="a">a</option>
20 <option value="b">b</option>
21 <option value="c">c</option>
22 </select>
23 </body>
24 </html>
一个普通的ASPX的页面,运行没有任何问题,但是放到WebPart中,你试试,change事件不激发了?
解决的办法有两个:
- 在SharePoint的母板页中的最上面加上如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- 修改JavaScript代码,如下:
代码function test() {
var s = document.getElementById("select1");
s.onchange = show;
}
function show() {
var s = window.event.srcElement;
alert(s.value);
}