为文字控件创建动态文本
在列表视图事件的 ListView1_ItemDataBound 上,我像这样创建literal.text...
<span style="position:relative;">
style="position:relative">
<span id="term1" class="popup">This id="term1" class="popup">This is the answer!</span>
<a href="javascript:void(0);"onMouseover="ShowPop('term1');" onMouseout="HidePop('term1');">Show href="javascript:void(0);"onMouseover="ShowPop('term1')" onMouseout="HidePop('term1')">Show me the answer</a></span>
问题是文本没有按应有的方式呈现。 将鼠标悬停在文字控件上时,网址为
http://localhost:1391/"javascript:void(0);"onMouseover="ShowPop('term1');"
那么这里发生了什么?我缺少什么?
更新1: 这是浏览器的来源
<span style="position:relative;"> <span id="term1" class="popup">This is the answer!</span> <a href="javascript:void(0);" onMouseover="ShowPop('term1');" onMouseout="HidePop('term1');">Show me the answer</a></span>
UPDATE2: 这是屏幕的输出
This is the answer Show me the answer
,其中...
显示答案 是指向 http://localhost:1391/"javascript:void(0);"
On the ListView1_ItemDataBound of a list view event, i create the literal.text like so...
<span style="position:relative;">
style="position:relative">
<span id="term1" class="popup">This id="term1" class="popup">This is the answer!</span>
<a href="javascript:void(0);"onMouseover="ShowPop('term1');" onMouseout="HidePop('term1');">Show href="javascript:void(0);"onMouseover="ShowPop('term1')" onMouseout="HidePop('term1')">Show me the answer</a></span>
The problem is that the text is not rendered as it should. On mousing over the literal control the url is
http://localhost:1391/"javascript:void(0);"onMouseover="ShowPop('term1');"
So what is going on here? What am i missing?
UPDATE1:
Here is the source from the browser
<span style="position:relative;"> <span id="term1" class="popup">This is the answer!</span> <a href="javascript:void(0);" onMouseover="ShowPop('term1');" onMouseout="HidePop('term1');">Show me the answer</a></span>
UPDATE2:
And here is the output from the screen
This is the answer Show me the answer
where...
Show me the answer is the hyperlink to http://localhost:1391/"javascript:void(0);"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
href
属性末尾和onMouseOver
属性之间缺少空格。更新:(以下评论)
将鼠标悬停在链接上时,某些浏览器会显示
href
属性指向的位置。在这种情况下,这将是“javascript:void(0);”。有些会将主机 URL 附加到此预览中,有些则不会。更新2:(以下更新回答)
看起来框架是对您正在使用的字符串进行HTML编码。确保设置
文字控件的 Mode
属性为LiteralMode.PassThrough
。更新3:(经过一些测试)
我尝试在本地使用带引号的字符串,没有任何问题。您确定在设置文本属性之前没有进行 HTML 编码,或者它不是经过编码的吗?在设置文本属性之前尝试 HTML 解码。
You are missing a space between the end of the
href
attribute and theonMouseOver
attribute.Update: (following comment)
When hovering over a link, some browsers will show you where the
href
attribute points. In this case this would be "javascript:void(0);". Some will append the host URL to this preview, some will not.Update 2: (following update to answer)
Looks like the framework is HTML Encoding the strings you are using. Make sure you set the
Mode
property of the literal control toLiteralMode.PassThrough
.Update 3: (following some testing)
I tried locally using string with quotes and had no problem. Are you sure you are not HTML encoding before setting the text property, or that it isn't coming in encoded? Try HTML decoding before setting the text property.