簡體   English   中英

使用此值在選項選擇上獲取腳本

[英]Get script on option select with this value

我正在使用一個選擇框來提取站點中內置的一些數據。 但是,有一些模塊可以運行腳本,並使用select選項,該腳本在被選擇時不會觸發。 我是否必須在我的option函數中運行完整腳本,還是可以選擇它來調用它再次執行。

這是我的腳本和HTML。 選項值“ MESSAGE12”-選擇后需要運行腳本。

if(unescape(location.href).indexOf("http://football")!=-1||unescape(location.href).indexOf("http://6")!=-1) { 
    var currentServer=baseURLDynamic;
    xmlBaseURL = baseURLDynamic + '/fflnetdynamic' + year + '/';
} else {
    var currentServer=baseURLStatic;
}
function getHomePageModule(thisSelection) {
    if(thisSelection=="")
    document.getElementById("homePageModule").innerHTML = "Your selected module will appear here!";
    else {
    var url = currentServer + "/" + year + "/home/" + league_id + "?MODULE=" + thisSelection.toUpperCase();
    $.get(url, function(data){
    document.getElementById("homePageModule").innerHTML = $(data).find('#pageContent').html();
    });
    }
}    


<select onchange="getHomePageModule(this.value)">
<option value="default">Select A Module</option>
<option value="MESSAGE12" >Get HPM#12</option>
<option value="LIVESCORING" >Link To Live Scoring</option>
<option value="LIVESCORING_SUMMARY" >Live Scoring Summary</option>
</select>

<div id="homePageModule">Your selected module will appear here!</div>

這是我的演示選擇框的鏈接-http://football29.myfantasyleague.com/2015/home/72758?MODULE=MESSAGE11

我想在選擇框中啟動MESSAGE12內容的鏈接http://football29.myfantasyleague.com/2015/home/72758?MODULE=MESSAGE12

任何建議表示贊賞

您可以嘗試使用jQuery的.append()方法,而不是使用innerHTML不評估<scripts> )。

更改:

document.getElementById("homePageModule").innerHTML = $(data).find('#pageContent').html();

至:

$("#homePageModule").append($(data).find('#pageContent').html());

(這也用jQuery選擇器替換了對getElementById的調用。)

如果這樣不起作用,則可能需要查看對$(data).find('#pageContent').html()的調用返回的內容,並確保腳本在那里,和/或移動將腳本轉換為.append()完成后可以調用的函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM