我可以使用以下代码来获取所选文本:
text=window.getSelection(); /// for Firefox
text=document.selection.createRange().text; /// for IE
但是如何获得所选的Html,其中包括text和html标签?
我在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而在这里正常工作?
如果是Firefox,我可以使用它在表单(submitquestion)中设置文本区域(selectedtext)值,但在IE中失败.
document.submitquestion.selectedtext.value = txt;