0

我有下面给出的代码。它让我删除前 6 个字符可以正常工作。现在我想在 jquery 中添加代码以删除 < > 之间的文本

例子:

请帮忙。

<html>
<head>

<script type="text/javascript">
function showName(sel){
   var str='';
   for (var i=0;i<sel.options.length;i++){
       if (sel.options[i].selected){
           str+=(str!='') ? ', '+sel.options[i].value.slice(6) : sel.options[i].value.slice(6);
       }
   }
   sel.form.selectedFruities.value = str;
}
</script>

</head>
<body>
<select style='width: 925px' value='<?php if( $_SERVER['REQUEST_METHOD'] === 'POST' ) { print_r($_POST['users']); } ?>' name='users[]' onchange='showStaffno(this); showEmail(this); showName(this)' multiple>

<?php

$VoCatQrys = "SELECT * FROM manage where status = 1";
$VoCatdbResults = mysql_query($VoCatQrys);
    while($VoCats = mysql_fetch_array($VoCatdbResults ))
    {
?>

        <option class='h4' value='<?php print($VoCats[3]);echo",";print($VoCats[5]);echo" <";print($VoCats[9]);echo">"; ?>'>

    <?php print($VoCats[5]);echo" ( ";print($VoCats[9]);echo" )"; ?>
        </option>

        <?php
        }
        ?>
</select>

<input type="text" id="name" name="selectedFruities" size="131" > 

</form>

</body>
</html>
4

3 回答 3

1

尝试

function showName(sel) {
    var strs = [], opt;
    for (var i = 0; i < sel.options.length; i++) {
        opt = sel.options[i];
        if (opt.selected) {
            strs.push(opt.value.slice(6).replace(/<.*?>/, ''))
        }
    }
    sel.form.selectedFruities.value = strs.join();
}
于 2013-09-30T08:38:36.427 回答
0

尝试使用 PHP 的 substr() 函数

 $string = '<string>';
 $length = strlen($string);
 //subtract 2 from the length since the first char is being cut off and we're not including the final eithet
 $final = substr($string, 1, $length-2);

或者在 JS 中

var str = "<string>";
var length = str.length;
var final = str.substr(1, parseInt(length-2));

更多信息在这里这里

于 2013-09-30T08:41:54.367 回答
-3

To remove html tags, use strip_tags

于 2013-09-30T08:37:17.127 回答