这个脚本片段有什么问题?
收到验证错误:错误:属性规范必须以名称或名称标记开头
,但我不能挑剔它,我认为它需要新的眼光!
该脚本位于 PHP 页面上的 标记内,因此 PHP 执行得很好。
var Target = ' target="_blank"';
var twtTitle = "I am going to <?php echo $fb_title;?>";
var tinyUrl = "<?php
echo getTinyUrl(curPageURL());?>";
document.write('<a class="twitter" href="'+twtLink+'"'+Target+'><img src="<?php echo bloginfo('template_url'); ?>/style/images/social/twitter.png" border="0" alt="Tweet This!" /> <span class="link_text"> Tweet this event</span></a>');
以下是服务器呈现的所有变量(PHP 后)
var Target = ' target="_blank"';
var twtTitle = "I am going to Teenage 16-19";
var tinyUrl = "http://tinyurl.com/6eem8qc";
var twtLink = 'http://twitter.com/home?status='+encodeURIComponent(twtTitle + ' ' + tinyUrl + " via @WaggleB"+ "");
添加警报以显示 twtLink 的值,该值显示为
http://twitter.com/home?status=I%20am%20going%20to%20Teenage%2016-19%20http%3A%2F%2Ftinyurl.com%2F6eem8qc%20via%20%40WaggleB
Getting the validation error: Error: an attribute specification must start with a name or name token
but I can't fault it, I think it needs fresh eyes!!
The script is located within <script>
tags on a PHP page, so the php is executing just fine.
var Target = ' target="_blank"';
var twtTitle = "I am going to <?php echo $fb_title;?>";
var tinyUrl = "<?php
echo getTinyUrl(curPageURL());?>";
document.write('<a class="twitter" href="'+twtLink+'"'+Target+'><img src="<?php echo bloginfo('template_url'); ?>/style/images/social/twitter.png" border="0" alt="Tweet This!" /> <span class="link_text"> Tweet this event</span></a>');
Here are all the vars as rendered by the server (post PHP)
var Target = ' target="_blank"';
var twtTitle = "I am going to Teenage 16-19";
var tinyUrl = "http://tinyurl.com/6eem8qc";
var twtLink = 'http://twitter.com/home?status='+encodeURIComponent(twtTitle + ' ' + tinyUrl + " via @WaggleB"+ "");
Adding an alert to show the value of twtLink
shows the value as
http://twitter.com/home?status=I%20am%20going%20to%20Teenage%2016-19%20http%3A%2F%2Ftinyurl.com%2F6eem8qc%20via%20%40WaggleB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有正确用引号关闭 href 属性。
http://validator.w3.org/docs/errors.html
问题更新后编辑
这看起来也非常可疑:
具体来说,变量 template_url 似乎位于另一对单引号内的单引号之间。
You did not close href attribute with a quotation mark properly.
http://validator.w3.org/docs/errors.html
EDIT AFTER QUESTION UPDATE
This also looks extremely suspicious:
Specifically, variable template_url that appears to be between single quotation marks inside another pair of single quotation marks.
尝试将脚本包含在
和
]]>
块中。根据您的文档类型,如果包含 html 标记的 javascript 字符串不在 cdata 块中,您可能会遇到问题。Try enclosing your script in
<![CDATA[
and]]>
blocks. Depending on your doctype, you might have an issue with javascript strings containing html tags if it's not in a cdata block.