我正在使用 iWeb 进行一些简单的网页开发,并将一些 JavaScript 放入 HTML 小部件中。我做的第一个小部件工作得很好,但第二个我遇到了问题。该脚本应该从 URL 中提取 $_GET 变量来寻址用户。我的脚本在 iWeb 之外完美运行,但是我将它复制到 iWeb 小部件中时失败了。这是我的代码:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
//Replace all String Function
String.prototype.replaceAll = function(search, replace){
//if replace is null, return original string otherwise it will
//replace search string with 'undefined'.
if(!replace)
return this;
return this.replace(new RegExp('[' + search + ']', 'g'), replace);
};
//GET from URL
var getVars = {},
args = location.search.substr(1).split(/&/);
for (var i=0; i<args.length; ++i){
var tmp = args[i].split(/=/);
if(tmp[0] != ""){
getVars[decodeURIComponent(tmp[0])] = decodeURIComponent(tmp.slice(1).join("").replaceAll("+", " "));
}
}
$(document).ready(function(){
$("#rsvpName").html(getVars["rsvpName"]);
if( getVars["rsvpResponse"] == "1" )
$("#rvspMessage").html( "You will be attending as part of a party of " + getVars["rsvpNum"] + "." );
else if( getVars["rsvpResponse"] == "0" )
$("#rvspMessage").html("We regret you will not be able to attend!");
alert( getVars["rsvpName"] + getVars["rsvpResponse"] + getVars["rsvpNum"]);
});
</script>
<h1>Thank you, <b><span id="rsvpName">Name</span></b>, for RSVPing.</h1>
<p id="rvspMessage">Message</p>
有人有建议吗?