<select name="n" onchange="if(this.selectedIndex != 0) window.location = this.options[this.selectedIndex].value">
<option value="url&param={param}">
<xsl:if condition>
<xsl:attribute name="selected">true</xsl:attribute>
</xsl:if>
</option>
</select>
The code above works fine, it passes selected option to url. The only problem is that when the parameter contains '&' sign in between. How do I pass parameter when it's value is something like 'A & B'? urlencode seems not helpful? Thanks for your time!
上面的代码工作正常,它将选定的选项传递给url。唯一的问题是当参数包含'&'之间的符号时。如果参数值为'A&B',我如何传递参数? urlencode似乎没有用?谢谢你的时间!
1 个解决方案
#1
0
Tried urlencode(), but it returns double escaping error. Note that this question is not about to simply encode the whole url, but to escape some Special Characters for passing parameters. I had another situation, in which a parameter value has '+' sign in the string. I figured that it's probably better to show the string but return a nameid something as the value, which is int. My option value changed to something like this:
尝试了urlencode(),但它返回双重转义错误。请注意,这个问题不是简单地编码整个URL,而是为了传递一些特殊字符来传递参数。我有另一种情况,其中参数值在字符串中有'+'符号。我认为显示字符串可能更好,但返回一个nameid作为值,即int。我的选项值更改为以下内容:
<select onchange="if(this.selectedIndex != 0) window.location = this.options[this.selectedIndex].value">
<option value="" selected="selected"><xsl:value-of select="/A/D/NAME"/></option>
<xsl:for-each select="/A/B/C">
<option value="URL&Name={NAME}&ID={ID}"
<xsl:if test="NAME=/A/D/NAME"><xsl:attribute name="selected">true</xsl:attribute></xsl:if>
<xsl:value-of select="NAME"/>
</option>
</xsl:for-each>
</select>
The url now have the Id as the parameter2 matching the parameter1(Name). And I can use this Id to search the database and return the string(Name) to show again. This doesn't directly answer the question, but does provide a workaround.
url现在将Id作为与parameter1(Name)匹配的parameter2。我可以使用此Id来搜索数据库并返回字符串(Name)以再次显示。这并没有直接回答这个问题,但确实提供了一种解决方法。
#1
0
Tried urlencode(), but it returns double escaping error. Note that this question is not about to simply encode the whole url, but to escape some Special Characters for passing parameters. I had another situation, in which a parameter value has '+' sign in the string. I figured that it's probably better to show the string but return a nameid something as the value, which is int. My option value changed to something like this:
尝试了urlencode(),但它返回双重转义错误。请注意,这个问题不是简单地编码整个URL,而是为了传递一些特殊字符来传递参数。我有另一种情况,其中参数值在字符串中有'+'符号。我认为显示字符串可能更好,但返回一个nameid作为值,即int。我的选项值更改为以下内容:
<select onchange="if(this.selectedIndex != 0) window.location = this.options[this.selectedIndex].value">
<option value="" selected="selected"><xsl:value-of select="/A/D/NAME"/></option>
<xsl:for-each select="/A/B/C">
<option value="URL&Name={NAME}&ID={ID}"
<xsl:if test="NAME=/A/D/NAME"><xsl:attribute name="selected">true</xsl:attribute></xsl:if>
<xsl:value-of select="NAME"/>
</option>
</xsl:for-each>
</select>
The url now have the Id as the parameter2 matching the parameter1(Name). And I can use this Id to search the database and return the string(Name) to show again. This doesn't directly answer the question, but does provide a workaround.
url现在将Id作为与parameter1(Name)匹配的parameter2。我可以使用此Id来搜索数据库并返回字符串(Name)以再次显示。这并没有直接回答这个问题,但确实提供了一种解决方法。