小编use*_*494的帖子

如何用javascript选择html文本?

我可以使用以下代码来获取所选文本:

text=window.getSelection(); /// for Firefox text=document.selection.createRange().text; /// for IE

但是如何获得所选的Html,其中包括text和html标签?

javascript getselection

37
推荐指数
3
解决办法
7万
查看次数

json_decode为字符串变量返回NULL

我在json_decode上遇到了一个非常奇怪的问题,使用以下代码:

$url="http://localhost:8983/solr/db/select?wt=json&rows=1&q=94305";
$string=file_get_contents($url);
echo $string; echo '<br><br>';
$json=json_decode($string);
var_dump($json);
Run Code Online (Sandbox Code Playgroud)

我得到了以下结果:

{"responseHeader":{"status":0,"QTime":0,"params":{"q":"94305","wt":"json","rows":"1"}},"response":{"numFound":165,"start":0,"docs":[{"price":"","tags":"ATMs","phone_n":"","location":"37.42409897,-122.1709976 ","store":"Discover ATM","store_id":"478602","state":"CA","latitude":"37.42409897","address":"459 LAGUNITA","zipcode_n":"94305","longitude":"-122.1709976\r","url":"Discover_ATM_459_LAGUNITA_Stanford_CA_94305","city":"Stanford","category":"ATMs","text":["","CA","459 LAGUNITA","94305","Stanford"],"spell":["Discover ATM"]}]}}

NULL 
Run Code Online (Sandbox Code Playgroud)

看来我不能json_decode这个字符串.但是,当我这样做时(复制上面的字符串的输出并将其直接放到$ string):

$string='{"responseHeader":{"status":0,"QTime":0,"params":{"q":"94305","wt":"json","rows":"1"}},"response":{"numFound":165,"start":0,"docs":[{"price":"","tags":"ATMs","phone_n":"","location":"37.42409897,-122.1709976 ","store":"Discover ATM","store_id":"478602","state":"CA","latitude":"37.42409897","address":"459 LAGUNITA","zipcode_n":"94305","longitude":"-122.1709976\r","url":"Discover_ATM_459_LAGUNITA_Stanford_CA_94305","city":"Stanford","category":"ATMs","text":["","CA","459 LAGUNITA","94305","Stanford"],"spell":["Discover ATM"]}]}}';
$json=json_decode($string);
var_dump($json);
Run Code Online (Sandbox Code Playgroud)

json_decode有效.为什么json_decode在第一部分得到NULL而在这里正常工作?

php json

7
推荐指数
1
解决办法
3902
查看次数

如何使用javascript在IE中的表单中设置文本区域值

如果是Firefox,我可以使用它在表单(submitquestion)中设置文本区域(selectedtext)值,但在IE中失败.

document.submitquestion.selectedtext.value = txt;

javascript internet-explorer text area

5
推荐指数
1
解决办法
4万
查看次数

标签 统计

javascript ×2

area ×1

getselection ×1

internet-explorer ×1

json ×1

php ×1

text ×1