0

再会,

我可以知道是否有可能/是否存在允许某些文本说带有 # 的 UIkit 是可点击的?

例如:

text# hello world 在文本区域内,由一些 php get 脚本填充。我希望#text# 是可点击的,并且应该执行一些操作。

4

1 回答 1

0

Here is one method by which you can make some part of the content of a textarea clickable. Here we are not using a textarea. instead we use a div with contentEditable=true. Then we change the style of the div so that it looks like a text area. now with javascript you can replace the words inside the div with anchor tags..

<style type="text/css">
    #editableDiv {
        -moz-appearance: textfield;
        -webkit-appearance: textfield;
        background-color: white;
        background-color: -moz-field;
        border: 1px solid darkgray;
        box-shadow: 1px 1px 1px 0 lightgray inset;
        font: -moz-field;
        font: -webkit-small-control;
        margin-top: 5px;
        padding: 2px 3px;
        width: 398px;
    }
</style>

<div id="editableDiv" contenteditable="true">This is a paragraph. It is editable. Try to change this #text. <a href="www.google.com">click here</a>

</div>
<button type="button" onclick="displayResult()">Click here to change the content</button>
<script>
    function displayResult() {
        var x = document.getElementById("editableDiv").innerHTML;
        var m = x.replace("#text", "<a href ='#'>replaced text</a>");
        document.getElementById("editableDiv").innerHTML = m;
    }
</script>

In the above javascript code instead of #text you can use regular expressions also

于 2013-08-28T06:39:47.937 回答