简体   繁体   English

Twitter分享中的jquery串联问题

[英]jquery concatenation issue in twitter share

jQuery(document).ready(function() { jQuery(document).ready(function(){

                        jQuery('#twitter_share').on('click',function (e) {
                            e.preventDefault();
                            //share image
                            var share_image = jQuery('#share_image').val();    

                            var share_image_link = "http://<?php echo $base_url;?>?photo=" +share_image;

                            //alert(share_image_link);                          
                            //tweet content
                            //var tw_text = "Lorem Ipsum @Monkeypig Ipsum has been the industry's standard http://<?php echo $base_url;?>?photo=" +share_image;

                            var tw_text = "Lorem Ipsum @Monkeypig Ipsum has been the industry standard <a href=' + share_image_link +  '> + share_image_link + </a>"; 

                            //alert(tw_text);
                            //'<p>page , <a href="http://www.myaddress.com/' + pageno + '">link</a> </p>'

                            //tweet link
                            var twtLink = "https://twitter.com/intent/tweet?text=" +tw_text;

                            //open new window
                            window.open(twtLink);
                        });
                    });

I want to share some content with link in twitter.But i am faceing some concatenation issue here var tw_text = "Lorem Ipsum @Monkeypig Ipsum has been the industry standard + share_image_link + "; 我想通过Twitter中的链接共享一些内容。但是我在这里面临着一些串联问题var tw_text =“ Lorem Ipsum @Monkeypig Ipsum已经成为行业标准+ share_image_link +” Where i am doing wrong.I need help. 我做错了的地方。我需要帮助。

You did face a string delimiter issue. 您确实遇到了字符串定界符问题。 Here's a model : 这是一个模型:

myVar='variable';
alert("here's a string and then the content of a " + myVar + ".");

So in your case : 因此,在您的情况下:

var tw_text = "Lorem Ipsum @Monkeypig Ipsum has been the industry standard <a href=' + share_image_link +  '> + share_image_link + </a>"; 

Should be : 应该 :

var tw_text = "Lorem Ipsum @Monkeypig Ipsum has been the industry standard <a href='" + share_image_link +  "'>" + share_image_link + "</a>"; 

Look carefully, with a highlight syntax editor such as notepad++ to understand how this is working in detail. 使用高亮语法编辑器(例如notepad ++)仔细查看,以详细了解其工作方式。

应该:

var tw_text = "Lorem Ipsum @Monkeypig Ipsum has been the industry standard <a href=" + share_image_link + '>' + share_image_link + "</a>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM