它適用於我的小提琴http://jsfiddle.net/JustJill54/XFaaG/11/,但不會當我添加的jQuery代碼CEWP。 (僅供參考,我只是把jQuery的在CEWP的概念驗證。) 唯一的區別,當我在結果顯示SRC的小提琴,是Window.Load()事件是存在的,所以我嘗試添加該事件給我的CEWP ,但警報仍然不起作用。jQuery的警告在HTML工作,不工作的時候添加到SharePoint CEWP
這裏的代碼CEWP
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
$(document).ready(function() {
$("tr.reqDet").hide();
$("tr.anon").hide();
$("tr.actDet").hide();
// Attach to the focusout event of the select, if that's when
// you want to check the value
$("select[title='organizationalElement']").focusout(function() {
// Now see if it's the value you want
if ($(this).val() === 'idk') {
alert("If no organizational element is selected, additional time may be required to route this request");
} //close if
$("select[title='requestType']").change(function() {
$(".reqDet").toggle($(this).val() !== "");
}); //close requestType
$("select[title='anonymous']").change(function() {
$(".anon").toggle();
}); //close anonymous
$("select[title='action']").change(function() {
$(".actDet").toggle($(this).val() !== "");
}); //close action
}); //close select.focusout
}); //close doc.ready
}); //close window.load
</script>
更新:我已經註釋掉了我所有的邏輯,只是試圖讓警報顯示在頁面加載時,我還沒有能夠得到它的工作。
UPDATE2:我創建了一個與我的SharePoint頁面具有相同控件的.html頁面,並添加了jQuery腳本來顯示頁面加載時的警報,甚至是那個工作,但帶有SharePoint的.aspx頁面:FormField控件不是加工。
UPDATE3:我引用一個JavaScript教程和修訂我的腳本。主要區別在於NOT EQUAL運算符已被更改爲!=,而我註釋掉了Window.load事件。這是我修改後的腳本:
//$(window).load(function(){
$(document).ready(function(){
$("tr.reqDet").hide();
$("tr.anon").hide();
$("tr.actDet").hide();
$("select[title='organizationalElement']").focusout(function() {
if ($(this).val() === 'idk') {
alert("If no organizational element is selected, additional time may be required to route this request");
} // close if
$("select[title='requestType']").change(function() {
$(".reqDet").toggle($(this).val() != "");
}); //close requestType.change
$("select[title='anonymous']").change(function(){
$(".anon").toggle();
}); //close anonymous.change
$("select[title='action']").change(function(){
$(".actDet").toggle($(this).val()!= "");
}); // close action.change
});//close select.focusout
}); // close doc.ready
//}); // close window.load
UPDATE4:我用螢火蟲來獲得選擇的VAL,並意識到它沒有返回「IDK的」(由SP的列表項的值指定),但返回「我不不知道「。這引發了另一個問題/提醒我,我將不需要轉義撇號(')。無論如何,仍然在扭結...
UPDATE5:@ Janis-我不能看到我的腳本在螢火蟲的腳本選項卡...所以我想這意味着它沒有被執行。
BTW。這是UPDATE4之後腳本的狀態。
$(window).load(function(){
$(document).ready(function(){
$("tr.reqDet").hide();
$("tr.anon").hide();
$("tr.actDet").hide();
$("select[title='organizationalElement']").focusout(function() {
if ($(this).val() === "I don\'t know") {
alert("If no organizational element is selected, additional time may be required to route this request");
} // close if
$("select[title='requestType']").change(function() {
$(".reqDet").toggle($(this).val() != "");
}); //close requestType.change
$("select[title='anonymous']").change(function(){
$(".anon").toggle();
}); //close anonymous.change
$("select[title='action']").change(function(){
$(".actDet").toggle($(this).val()!= "");
}); // close action.change
});//close select.focusout
}); // close doc.ready
}); // close window.load
任何想法爲什麼?我以爲我使用了總是被稱爲(doc.ready,window.load)的非常普通的事件。
UPDATE6:天啊......終於來了!猜猜第六次是魅力。我肯定會填補每個人都對我工作.... 不管怎麼說,修訂後的腳本如下:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
$(document).ready(function(){
$("tr.reqDet").hide();
$("tr.anon").hide();
$("tr.actDet").hide();
$("select[title='organizationalElement']").focusout(function() {
if ($(this).val() === "I don\'t know") {
alert("If no organizational element is selected, additional time may be required to route this request");
} // close if
$("select[title='requestType']").change(function() {
$(".reqDet").toggle($(this).val() != "");
}); //close requestType.change
$("select[title='anonymous']").change(function(){
$(".anon").toggle();
}); //close anonymous.change
$("select[title='action']").change(function(){
$(".actDet").toggle($(this).val()!= "");
}); // close action.change
});//close select.focusout
}); // close doc.ready
}); // close window.load
</script>
粘貼,而不是直接進入CEWP,我把它上傳的.js文件到我創建的一個名爲SiteAssets的文件夾(在我們遷移到SPD2010的情況下),並通過CEWP的內容鏈接調用所述文件... js。使用Firebug驗證腳本正在加載。
所以,有些事情我已經瞭解得到這個jQuery腳本用於在我SP頁與工作
- 不要以爲你知道什麼VAL正在螢火蟲來returned--使用控制檯選項卡得到正確的結果
- 檢查你的語法
- 即使在... js文件中引用jQuery代碼,確保它啓動w /必需的標籤,ow你可能會以腳本的形式將腳本插入頁面底部 希望這有助於你!
在Firebug中,你能看到你的自定義腳本(你剛剛粘貼的代碼在這裏)嗎? – 2011-12-19 07:56:51