第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使一段文本中的鏈接充當(dāng)實(shí)際鏈接?

如何使一段文本中的鏈接充當(dāng)實(shí)際鏈接?

犯罪嫌疑人X 2023-11-12 15:39:47
我有一個(gè)應(yīng)用程序,用戶(hù)在其中輸入可能包含鏈接的文本(我所說(shuō)的鏈接是指只有以 https 開(kāi)頭的鏈接...)。然后這個(gè)輸入會(huì)變成文本,以便用戶(hù)可以閱讀。不過(guò),我希望本文中的鏈接作為實(shí)際鏈接使用。我只有一個(gè)文本作為字符串,并且希望所有非鏈接文本都保留為文本。如果你知道制作方法請(qǐng)告訴我
查看完整描述

2 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

它看起來(lái)像這樣 https://snack.expo.io/@webspaceteam/juicy-cookie

import * as React from 'react';

import {

  Text,

  View,

  StyleSheet,

  TouchableOpacity,

  Linking,

} from 'react-native';

import Constants from 'expo-constants';


// You can import from local files

import AssetExample from './components/AssetExample';


// or any pure javascript modules available in npm

import { Card } from 'react-native-paper';


export default function App() {

  const userText =

    'rfrfop referoif frefio remfie https://snack.expo.io/@webspaceteam/ea041b fjir frfrfr';

  const convert = () => {

    const urlRegex = /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/;


    return userText.split(/\s+/).map((word) => {

      if (urlRegex.test(word)) {

        return (

          <Text onPress={() => Linking.openURL(word)}>

            <Text style={{ color: 'blue' }}>{word}</Text>{' '}

          </Text>

        );

      } else {

        return (

          <>

            <Text>{word}</Text>{' '}

          </>

        );

      }

    });

  };

  return (

    <View style={styles.container}>

      <Text style={styles.paragraph}>{convert()}</Text>

      <Card>

        <AssetExample />

      </Card>

    </View>

  );

}


const styles = StyleSheet.create({

  container: {

    flex: 1,

    justifyContent: 'center',

    paddingTop: Constants.statusBarHeight,

    backgroundColor: '#ecf0f1',

    padding: 8,

  },

  paragraph: {},

});


查看完整回答
反對(duì) 回復(fù) 2023-11-12
?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊

getSelection()在事件偵聽(tīng)器中調(diào)用的函數(shù)內(nèi)使用。請(qǐng)參閱代碼中的注釋信息。


const article = document.getElementById("article");


// event listener that uses mouseup on a handlerFunction

article.addEventListener('mouseup', handlerFunction, false);


// Mouse up event handler function

function handlerFunction(event) {


  // Check if any text was selected using a conditional

  if (window.getSelection().toString().length > 0) {


    // Get selected text and its parent node

    const selection = window.getSelection().toString();

    const selectedEl = window.getSelection().anchorNode.parentNode;

    

    // regex patter for https website {{{MAY NEED WORK THIS JUST FOR EXAMPLE}}} 

    var pattern = new RegExp("^(https?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_\+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?");

    console.log(selection);

    

    // conditional to check if selection is in fact a https site

    // NOTE THIS CONDITIONAL REGEX WAS NOT TESTED THUROUGHLY

    // I SUGGETS YOU ADD YOUR OWN CONDITIONAL CHECK FOR HTTPS

    if (pattern.test(selection)){

    

      // Add link to selected text

      const addATag = '<li><a href="selection">' + selection + '</a></li>';


    // Append HTML to the selected element

    selectedEl.outerHTML = addATag;

  }

}

}

li {

   list-style-type: none;

}

<div id="article">

  <ul>

    <li>https://myspace.com</li>

    <li>https://www.mywebsite.com</li>

    <li>https://www.rumble.com</li>

  </ul>

</div>


查看完整回答
反對(duì) 回復(fù) 2023-11-12
  • 2 回答
  • 0 關(guān)注
  • 151 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)