2012-05-31 25 views
0

我想将ukaccess函数的返回值合并到由setarea函数设置的值中,但我没有足够的经验知道下一步该做什么。希望到目前为止,代码是正确的。如何将返回值与文本结合起来

function ukaccess(){ 

    var dbasedata = document.forms[0]._dbase_name.value; 
     dbasedata = dbasedata.toUpperCase(); 

    if (dbasedata.indexOf("UK_CONTACTS")>-1) { 
     return "UK_CONTACTS"; 
    } 
    } 


function setarea(){ 

    var postcode2 = document.forms[0]._postalcode.value; 
    var trim_pcode = (postcode2.substr(0,8)); 
     trim_pcode = trim_pcode.toUpperCase(); 
     trim_pcode = trim_pcode.replace(/\s/g, ""); 

    if (trim_pcode == "W1W6UW" || trim_pcode == "W1G8HU") { 
     //alert("London-Xover"); 
     document.forms[0]._area.value = "North London" [ukaccess function return value here]; 

回答

2

尝试

document.forms[0]._area.value = "North London" + ukaccess(); 
+0

千恩万谢,我已经试过了。在我猜的代码中必须有其他错误。 – labman

+0

您是否尝试将该值返回给其他变量,然后添加该值? var TEMP = ukaccess();然后document.forms [0] ._ area.value =“North London”+ TEMP;或者尝试使用JS中的concat方法http://www.w3schools.com/jsref/jsref_concat_string.asp – GreenGiant

+0

谢谢你。它最终确实起作用,在页面的另一部分我还有其他错误:-s哦,陡峭的学习曲线的乐趣。 – labman

相关问题