如何从输出字段中删除引号?

时间:2022-09-15 15:11:52

I made a simple 'click to tweet' tool which takes input, adds quotes in preview and tweet it on a button click. http://codepen.io/markoJurisic/pen/yJgVez

我做了一个简单的“点击推特”工具,它接受输入,在预览中添加引号并在按钮点击时发推。 http://codepen.io/markoJurisic/pen/yJgVez

Everything seems fine with input and output fields, except when you delete all text from the input field, quotes remain. I've tried to remove them, but unsuccessfully. This is my jquery code for the output field:

输入和输出字段似乎都很好,除非从输入字段中删除所有文本,引号仍然存在。我试图删除它们,但没有成功。这是我的输出字段的jquery代码:

var $src = $('#input'),
    $dst = $('#output');

    $src.on('input', function () {
        $dst.html('“' + $src.val() + '”');
    });

Also, is there any way to remove url from a generated tweet? e.g. if I type "Hello World!" and click to tweet to premade a message without a codepen url.

另外,有没有办法从生成的推文中删除网址?例如如果我输入“Hello World!”然后点击推文预制一条没有codepen网址的邮件。

1 个解决方案

#1


2  

You can use a ternary to check if the is anything in the input:

您可以使用三元组来检查输入中是否有任何内容:

$src.on('input', function () {
    $dst.html($src.val() ? '“' + $src.val() + '”' : '');
});

For the url exclusion you mentioned, if you are intending on having the user tweet instead of share, you should then be using intents - to do this simply change the url:

对于您提到的网址排除,如果您打算使用用户推文而不是共享,那么您应该使用意图 - 这样做只需更改网址:

tweetUrl = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(phrase); 

Note the use of https://twitter.com/intent/tweet instead of https://twitter.com/share

请注意使用https://twitter.com/intent/tweet而不是https://twitter.com/share

Updated Pen

#1


2  

You can use a ternary to check if the is anything in the input:

您可以使用三元组来检查输入中是否有任何内容:

$src.on('input', function () {
    $dst.html($src.val() ? '“' + $src.val() + '”' : '');
});

For the url exclusion you mentioned, if you are intending on having the user tweet instead of share, you should then be using intents - to do this simply change the url:

对于您提到的网址排除,如果您打算使用用户推文而不是共享,那么您应该使用意图 - 这样做只需更改网址:

tweetUrl = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(phrase); 

Note the use of https://twitter.com/intent/tweet instead of https://twitter.com/share

请注意使用https://twitter.com/intent/tweet而不是https://twitter.com/share

Updated Pen