我需要有关电子表格查询的帮助,其中可以从用户输入设置搜索条件。我已经更改了电子表格密钥,因为它是机密信息,但如果我手动输入MY VARIABLE的实际数字(在CONTAINS%20%27之后显示),代码就可以工作。
我需要帮助的是代码,该代码将用户输入id代替MY VARIABLE在其下方的查询中。有人可以帮忙吗?
<input type='text' id='userInput' value='Enter Text Here' />
<input type='button' onclick='javascript:changeText2()' value='Click here after you enter your Skyward Password'/>
Click on link to see your PRIDE info : <a href="https://spreadsheets.google.com/tq?tqx=out:html&tq=SELECT%20B%2C%20C%2C%20D%2C%20F%20WHERE%20D%20CONTAINS%20%27MY_VARIABLE%27&key=xxxxxgoogle spreadsheet keyFT7mL4DLX1xzeDsnzsbZG5jp4ZcWAOxU&gid=0" id=lnk>Click her for PRIDE info</a> <br>
答案 0 :(得分:0)
第一:不使用javascript:
<input type='button' onclick='changeText2()' value='Click here after you enter your Skyward Password'/>
如果你写的话会输出和错误:id = Ink而不是id =“Ink”
Click on link to see your PRIDE info : <a href="" id="Ink">Click her for PRIDE info</a> <br>
现在代码:
function changeText2(){
var ink = document.getElementById('Ink');
ink.href = "https://spreadsheets.google.com/tq?tqx=out:html&tq=SELECT%20B%2C%20C%2C%20D%2C%20F%20WHERE%20D%20CONTAINS%20%27" +encodeURIComponent(document.getElementById('userInput').value)+ "%27&key=xxxxxgoogle spreadsheet keyFT7mL4DLX1xzeDsnzsbZG5jp4ZcWAOxU&gid=0"
}
encodeURIComponent用于转义字符串。 简单,还是?