Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery-显示超链接文本_Jquery_Jquery Ui_Jquery Plugins - Fatal编程技术网

JQuery-显示超链接文本

JQuery-显示超链接文本,jquery,jquery-ui,jquery-plugins,Jquery,Jquery Ui,Jquery Plugins,正在查找有关显示用户选择的超链接的帮助。我试图做的是根据复选框选择的链接形成一个句子 所以应该是这样的 您已表示对写作支持、停车和住房感兴趣-这些关键词应该是链接 我已经研究并提取了一些代码,让它显示href,但不确定如何根据选择动态创建链接。谢谢你的帮助 <input type="checkbox" name="resource" value="Housing" href="http://housing.fake.com"> Housing</input> <in

正在查找有关显示用户选择的超链接的帮助。我试图做的是根据复选框选择的链接形成一个句子

所以应该是这样的

您已表示对写作支持停车住房感兴趣-这些关键词应该是链接

我已经研究并提取了一些代码,让它显示href,但不确定如何根据选择动态创建链接。谢谢你的帮助

<input type="checkbox" name="resource" value="Housing" href="http://housing.fake.com"> Housing</input>
<input type="checkbox" name="resource" value="Parking" href="https://Parking.fake.com"> Parking</input>
<input type="checkbox" name="resource" value="Writing Support" href="https://writing.fake.com"> Writing Support</input>


<div id="result"></div>

<input type="submit" id="submit" name="submit" value="Show Me the Resources">

var $result = $('#result');

$('input[type="submit"]').click(function () {
    var total = $('input[type="checkbox"]:checked').length;
    if (total <= 0 ) {
        $('#result').text('You have not indicated any interest. Please choose some options.');
    }
    else if (total == 1) {
        $('#result').text('You have indicated an interest in ' + $('input[type="checkbox"]:checked').attr('href') + '. Please click on the link to learn more about these resources.');
    } else {
        $('#result').text('You have indicated an interest in ');
        $('input[type="checkbox"]:checked').each(function(i) {
            if(i == total-1) {          
                $result.append('and ' + $(this).attr('href') + '.<br/> Please click on the links to learn more about these resources.');
            } else {
                $result.append($(this).attr('href') + ', ');
            }
        });  
    }
});
外壳
停车场
写作支持
var$result=$(“#result”);
$('input[type=“submit”]”)。单击(函数(){
var total=$('input[type=“checkbox”]:checked')。长度;
如果(总计请这样尝试:

$('#result').html('You have indicated an interest in ' + '<a href="' 
+ $('input[type="checkbox"]:checked').attr('href') + '">'
+ $('input[type="checkbox"]:checked').attr('href') + '</a> '
+ '. Please click on the link to learn more about these resources.');
$('#result').html('您表示对'+''感兴趣'
+“。请单击链接了解有关这些资源的更多信息。”);
像这样尝试:

$('#result').html('You have indicated an interest in ' + '<a href="' 
+ $('input[type="checkbox"]:checked').attr('href') + '">'
+ $('input[type="checkbox"]:checked').attr('href') + '</a> '
+ '. Please click on the link to learn more about these resources.');
$('#result').html('您表示对'+''感兴趣'
+“。请单击链接了解有关这些资源的更多信息。”);

我已经做了一天了,你在一分钟内就解决了!我感谢两个答案。他们最终解决了我的问题。非常感谢!不客气:)如果你需要帮助,不要犹豫;)我已经做了一天了,你一分钟就解决了!我感谢两个答案。他们最终解决了我的问题。非常感谢!不客气:)如果你需要帮助,不要犹豫;)