简体   繁体   English

如何根据文本区域中的文本使链接可点击或不可点击?

[英]How to make link clickable or unclickable base on text in textarea?

I'm developing website which allow user to insert text automatically to textarea when they click on link "Thank you" and "Good luck". 我正在开发一个网站,当用户单击链接“谢谢”和“祝你好运”时,他们可以自动在textarea中插入文本。 After they click on which link, that link will be hide. 当他们单击哪个链接后,该链接将被隐藏。 Now, i can insert text to textarea when they click on that link. 现在,当他们单击该链接时,我可以在textarea中插入文本。 What i want now if user does not click on that both link, the Tweet link below textarea will unclickable and after user click that both links, the Tweet link will be clickable. 我现在想要的是,如果用户不单击两个链接,textarea下面的Tweet链接将不可单击,而用户单击两个链接后,Tweet链接将可单击。

Here is my current code 这是我当前的代码

HTML 的HTML

<a class="click" href="">Thank you</a><span style="display: none;">Thank you</span>&nbsp;
<a class="click" href="">Good luck</a><span style="display: none;">Good luck</span><br/>
<textarea rows="5" cols="40" name="replycontent" id="replycontent"></textarea><br/>
<a id="tweet" href="#">Tweet</a>

Javascript Java脚本

$(".click").on('click',function(e) {
    e.preventDefault();
    $("#replycontent").append($(this).next('span').text() );
    $(this).hide();
})

Can anyone help me with the above requirement? 有人可以帮我解决上述要求吗?

Thank in advance. 预先感谢。

How about something like this: 这样的事情怎么样:

$('#tweet').click(function (e) {
    if ($('.click:visible').length > 0) {
        e.preventDefault();
    }
    else {
        alert('Need to click more');
    }
});

If the number of visible .click items is greater than zero, do nothing. 如果可见.click项的数量大于零,则不执行任何操作。 When it hits zero show a message. 当它达到零时,显示一条消息。

To remove href for anchor tag, 要删除锚标签的href,

$('#tweet').removeAttr('href'); $('#tweet')。removeAttr('href');

To add href for anchor tag, 要为锚标签添加href,

$("#tweet").attr("href", " http://www.google.com/ ") $(“#tweet”)。attr(“ href”,“ http://www.google.com/ ”“

Remove href tag when the page loads, add href when user clicks the first link. 页面加载时删除href标签,用户单击第一个链接时添加href。 If you want both ".click" links to be clicked you can add counter variable inside the function to track the clicks. 如果要同时单击两个“ .click”链接,则可以在函数内部添加计数器变量以跟踪点击。

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

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