这个脚本片段有什么问题?

发布于 2024-11-07 20:19:14 字数 1115 浏览 1 评论 0原文

收到验证错误:错误:属性规范必须以名称或名称标记开头,但我不能挑剔它,我认为它需要新的眼光!

该脚本位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度 2024-11-14 20:19:14

您没有正确用引号关闭 href 属性。

http://validator.w3.org/docs/errors.html

问题更新后编辑

这看起来也非常可疑:

'><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>'

具体来说,变量 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:

'><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>'

Specifically, variable template_url that appears to be between single quotation marks inside another pair of single quotation marks.

养猫人 2024-11-14 20:19:14

尝试将脚本包含在 ]]> 块中。根据您的文档类型,如果包含 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文