dongyingjiu0669 2013-11-04 13:44
浏览 36

textarea val()使用jquery编辑和删除字符串

i'm creating a link sharing that on bind() events of a specific textarea ( where i paste links ) it does an $.post ajax callback with a preview (in case of youtube or vimeo link). Basically, i would remove link into textarea each times that link is detected and preview is gotten.

this is the function that does the callback :

    $('#writer').bind('change keypress keyup keydown',function() {

   var value_= $('#writer').val();
            $('#thumb-temp').hide();


            $.post( 'checklink.php?', { string : value_ }, 
            function(response) {
                $('.writer').prepend(response);
                $('#thumb-temp').show();

    }).fail(function() { alert( "error" ) })
});

and the page checklink.php that should remove the link

<?
    $link = $_POST['string'];

            $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
            preg_match($reg_exUrl, $link, $url);

            $link = $url[0];
?>
<script>clearTextarea('<? echo $link ?>')</script>

and in the end the clearTextarea() function

function clearTextarea(url) {
var _textarea = $('#writer');
var _curVal     =   _textarea.val();
        var _curUrl =   url;
        var _regex      =   new RegExp( _curUrl , 'g' );
        var _newVal     =   _curVal.replace( _regex , '' );

        _textarea.val( _newVal );
}

Now, apparentely, this should works but nothing happens, any ideas ? I do not understand where I'm wrong :(

  • 写回答

4条回答 默认 最新

  • duanping2695 2013-11-04 13:51
    关注

    I'm not sure if you can run javascript that way (echoing from PHP). I would call it from the $.post directly.

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集