我对JS有基本的了解。我正在尝试使下面的两个功能一起工作,但我找不到解决方案。一个或另一个起作用,但不是两者一起起作用。
<script>
function random_string(size){
var str = "";
for (var i = 0; i < size; i++){
str += random_character();
}
return str;
}
function random_character() {
var chars = "0123456789abcdefghijklmnopqurstuvwxyzABCDEFGHIJKLMNOPQURSTUVWXYZ";
return chars.substr( Math.floor(Math.random() * 62), 1);
}
window.onload = function () {
var partnerurl = document.getElementById('field1');
uniqueid = document.getElementById('field2');
uniqueid.value = random_string(15);
partnerurl.value = "www.website.com"+uniqueid.value
};
</script>
<script>
var defaultHiddenFieldNameValue = "";
function getQueryStringParamValue(strQStrParam) {
var strURL = document.location.href;
var strQStrParamValue = "";
if (strURL.indexOf('?') != -1)
{
strQStrParamValue = strURL.substr(strURL.indexOf('?') + 1);
if (strQStrParamValue.indexOf(strQStrParam) != -1)
{
strQStrParamValue = strQStrParamValue.substr(strQStrParamValue.indexOf(strQStrParam));
strQStrParamValue = strQStrParamValue.substr(strQStrParamValue.indexOf('=') + 1);
if (strQStrParamValue.indexOf('&') != -1)
strQStrParamValue = strQStrParamValue.substr(0, strQStrParamValue.indexOf('&'));
return strQStrParamValue;
}else{
strQStrParamValue = defaultHiddenFieldNameValue;
return strQStrParamValue;
}
}else{
strQStrParamValue = defaultHiddenFieldNameValue;
return strQStrParamValue;
}
}
// Form name goes here
var form = "formname";
function setCampaign(){
var elqForm = document.forms[form];
//repeat for each field to populate
elqForm.elements['src'].value = getQueryStringParamValue('src');
}
window.onload = setCampaign;
</script>
非常感谢您的帮助!
干杯,
外汇